//
//  InviteCodeView.m
//  FbeeAPP
//
//  Created by dev-m on 2018/3/21.
//  Copyright © 2018年 mohao. All rights reserved.
//

#import "InviteCodeView.h"

@interface InviteCodeView()
{
    UILabel *codeL;
    UIButton *copy;
    
    NSString *invieCode;
}

@end

@implementation InviteCodeView

-(instancetype)initWithFrame:(CGRect)frame Code:(NSString *)code
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        invieCode = code;
        
        [self buildView];
    }
    
    return self;
}

-(void)buildView
{
    UIImageView *bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    bg.image = [UIImage imageNamed:@"invite_codeframe"];
    [self addSubview:bg];
    
    codeL = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.addTextColor(FBEE_COLOR_INFO).addFont([UIFont systemFontOfSize:25.0f]);
        make.addText(invieCode);
        [make sizeToFit];
        make.centerX = self.width/2;
        make.top = 10;
        [self addSubview:make];
    }];
    
    copy = [UIButton makeButton:^(TTButtonExtend *make) {
        make.addTitleColor(FBEE_COLOR_BLUE,UIControlStateNormal).addFont([UIFont systemFontOfSize:14.0f]);
        make.addTitle(@"点击复制邀请码");
        make.setFrame(CGRectMake(0, self.height - 40, self.width, 40));
        make.addTarget(self,@selector(onCopy));
        [self addSubview:make];
    }];
}

-(void)onCopy
{
    if ([NSString isEmptyString:invieCode]) {
        return;
    }
    
    UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
    [pasteboard setString:invieCode];
    [NoticePopHelper showNoticeText:NSLocalizedString(@"msgCopySuccess", nil)];
}

@end
